<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.dom.document</title>
	<link rel="stylesheet" type="text/css" href="../../test.css" />
	<script type="text/javascript" src="../../../ckeditor.js"></script>
	<script type="text/javascript" src="../../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[

CKEDITOR.test.addTestCase( (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert,
		arrayAssert = YAHOO.util.ArrayAssert;

	return {
		test_$ : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			assert.areSame( document, doc.$ );
		},

		test_appendStyleSheet : function()
		{
			var cssUrl = CKEDITOR.basePath + '_tests/';
			cssUrl += '_assets/sample.css';

			var doc = new CKEDITOR.dom.document( document );
			doc.appendStyleSheet( cssUrl );

			var links = document.getElementsByTagName( 'link' );

			for ( var i = 0 ; i < links.length ; i++ )
			{
				if ( links[i].href == cssUrl )
					return ;
			}

			assert.fail( 'The link element was not found' );
		},

		test_equals1 : function()
		{
			// Actually checks the real need for equals().
			var doc1 = new CKEDITOR.dom.document( document );
			assert.isFalse( doc1 == document );
		},

		test_equals2 : function()
		{
			// Actually checks the real need for equals().
			var doc1 = new CKEDITOR.dom.document( document );
			var doc2 = new CKEDITOR.dom.document( document );
			assert.isFalse( doc1 == doc2, 'doc1 == doc2' );
		},

		test_equals3 : function()
		{
			var doc1 = new CKEDITOR.dom.document( document );
			var doc2 = new CKEDITOR.dom.document( document );
			assert.isTrue( doc1.equals( doc2 ), 'doc1.equals( doc2 )' );
			assert.isTrue( doc2.equals( doc1 ), 'doc2.equals( doc1 )' );
		},

		test_getById1 : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			var element = doc.getById( 'test1' );
			assert.areSame( document.getElementById( 'test1' ), element.$ );
		},

		test_getById2 : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			var element = doc.getById( 'test_invalid' );
			assert.isNull( element );
		},

		test_getHead : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			assert.areSame( document.getElementsByTagName( 'head' )[0], doc.getHead().$ );
		},

		test_getBody : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			assert.areSame( document.body, doc.getBody().$, '1st call failed' );
			assert.areSame( document.body, doc.getBody().$, '2nd call failed' );
		},
		test_createText : function()
		{
			var doc = new CKEDITOR.dom.document( document ), contentText = 'text content';
			var textNode = doc.createText( contentText );
			assert.areSame( contentText, textNode.getText(),
				'Create text node content doesn\'t match.' );
		},

		test_getByAddress1 : function()
		{
			var doc = new CKEDITOR.dom.document( document );
			var node = doc.getByAddress( [ 1, 1, 0, 1, 0, 0 ] );
			assert.areSame( 'target', node.getText(),
				'Addressing target doesn\'t match.' );
		},

		test_getElementsByTag : function()
		{
			var nodeList = new CKEDITOR.dom.document( document ).getElementsByTag( 'span' ),
				results = [];
			for( var i = 0; i < nodeList.count(); i++ ){
				results.push( nodeList.getItem( i ).$ );
			}
			arrayAssert.itemsAreEqual( results, document.getElementsByTagName( 'span' ) );
		},

		name : document.title
	};
})() );

	//]]>
	</script>
</head>
<body><div id="test1"></div><div><p>text<span><b id="addressTarget1">target</b>text</span>text</p></div><span ><b id="addressTarget2">target</b></span></body>
</html>
